<template>
  <div class="app-container">
    <el-form ref="form" :model="form" label-width="100px">
      <el-form-item label="使用状态" prop="use">
        <el-switch v-model="form.use" active-color="#00E266"></el-switch>
      </el-form-item>
      <el-form-item label="APPID" prop="appId">
        <el-input type="text" v-model="form.appId" placeholder="请输入APPID" />
      </el-form-item>
      <el-form-item label="商户私钥" prop="privateKey">
        <el-input type="textarea" autosize v-model="form.privateKey" placeholder="请输入商户私钥" />
      </el-form-item>
      <el-form-item label="公钥" prop="publicKey">
        <el-input type="textarea" autosize v-model="form.publicKey" placeholder="请输入公钥" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer" style="text-align: center">
      <el-button type="primary" @click="submitForm">保 存</el-button>
    </div>
  </div>
</template>

<script>
  import { getAlipayInfo, saveAlipayInfo } from "@/api/shuiyin/shuiyin";

  export default {
    name: "AlipayManage",
    data() {
      return {
        // 支付宝参数
        form: {},
      };
    },
    created() {
      this.getInfo();
    },
    methods: {
      /** 查询支付宝支付设置信息 */
      getInfo() {
        getAlipayInfo(this.queryParams).then(response => {
          if (response.data) {
            this.form = response.data;
          } else {
            this.form = {
              appId: '',
              privateKey: '',
              publicKey: '',
              use: false
            }
          }
        });
      },
      /** 保存按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            saveAlipayInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getInfo();
            });
          }
        });
      },
    }
  };
</script>
